Hello.
Welcome to this video.
In this video we will be adding the javascript functionality to make BMI calculator work.
Javascript relies on hasty e-mail has some time here says to be in place before he can work.
So we've already caused csx.
We've also got his mail already in place.
So let's go ahead and add our javascript.
So this is our code so far.
This is our Sears says PCs.
The hastier email so let's add our javascript.
We've already made a reference to our javascript inside our hastier mail file courtesy of this great
tag here online.
Thirty two.
So to create a new file a click on File go new.
And I'm going to save these as a jab as crip farts do file save as is going to save into the same directory
as RC SS and hastier mail.
I am going to call this b.
I dont.
G.
S in the dropdown.
Im just going to say let java script which is this one here.
Another click.
See.
So the I going to be added into this file is going to be javascript.
See the bottom right here says javascript saw I am already pre stage to code.
I'm going to add it on and I'll explain the code line by line.
So here I have had the javascript code that all make the BMI calculator work.
So let me run for the code with you on line two here.
I've got a comment so anything that is a comment is ignored when the code executes.
So this is a jab us group comment.
So this this is what is known as a single line comment.
So we could rantz it all just skip this comment and ignore it.
Comments are useful because they help you explain your code to yourself and also to others.
So here on line two is what is known as the formula for calculating the BMI.
Okay so here B W is the weight.
So basically the BMI formula is KG divided by height.
Of a hundred times.
Height divided by 100.
Okay so this is basically how you lead the BMI.
You do it as big fat which is in parentheses the height divided by a hundred times higher divided by
100 hundred and then you divide that value back.
The value in KG will give you a B.
So this cagy basically is to wait.
So this is the weight divided dividing the weight by the height.
So landfall here with me is in the document.
Get eliminated by Dean method.
And inside the premises we are passing them.
Submit submit physically is the botton here which is inside our heads here Mitchell document.
If I scroll down here you can see this I.D. submit.
That's what we're referring to inside this here.
So we put him in this cell mate and we have also caught an event listner.
So here we've got the AD event list.
Now the documents had Event this.
Now basically this is a method that attaches an event handler to the document and you can see we are
attaching a click event to the BMI later on.
Okay.
So here now what we're seeing here the event we are attaching to this is the click event and when the
bottom is click though this summary button is clicked on it all call this be my calculator.
All right.
This is a function which we are which I have defined here on line 5.
So I find it function it be my calculator.
And here have some variables here variables centimetre and we are using set in a causal pass end.
The path basically is a function that passes is drink and returns an integer k..
That's what we're doing here.
So we're passing a string.
What return in an integer integer is a number and we is in a documento get eliminate idae.
And the idea we're getting is the crm.
Again if we going to are his team now we can see we see this see omeir refers to the input.
So this implies here and this is a value.
So any input that is entered into that text box is what is going to be converted in to an integer value
because the hand text box is a tax.
So we're going to convert it to you as in this past it here we've got a variable called cagy we use
in the pass float.
The parse flood function passes is string and returns a floating point number.
This function determines the first character in the specified string is in number.
If it is it passes the string on till it reaches the end of the number and then returns the number as
in number and not drink.
That's what the Flook does.
Line 9 here defined in variable could be M.
I had a variable chord.
New seem set in the value of the variable here.
Can you see em to pass float had them passing in the value centimetre divided by a hundred.
Here the D BMI here variable B.
I am set in that he was to be kg which is is the variable here.
Divided by value which is this variable here time variable here as well.
Here I am 30 again.
The value of this BMI variable is going to change.
I am going to set the value to equal to wmi DOT to fixed basically the fixed method is used to convert
number into string.
Keep in a specified number of decimal.
In this case I have passed to 1 so it all have one decimal place consider log we don't necessarily need
that Disney's Glees for troubleshooting purposes.
So when you run your application you can see B value or so of the BMI inside consort.
This is not and is not mandatory.
You could actually comment that out or don't use it if you don't want to.
I tend to like it so I can see what's happening in the console as well.
Line 16 were worded document.
Don't get a lemon by day and the idea is a result of it going to the here.
Mail here.
This is what is referring to.
Okay so is getting the element BIOS result and is going to replace this Deve.
The calculated value of the.
My using the enhanced or tcom how to set the value of the BMI is on the calculated inputs.
So that is basically it.
So I'm just gonna say this and then we go and test to make sure everything works.
Someone opened up the directory here and click on the BMI page.
TMF far this one.
So each time you after a fight it is the history of file that you run.
And dont forget that from here a mail file I have linked but this he says and is javascript just going
to double click on that and we can see.
I'm just going to test its height in centimetre so I see 1 7 7 kg.
I say maybe 85 a clear cut lead.
I can see the value there.
Okay so we've got our BMI calculator working as designed so basic for this project.
If you have any issues whatsoever please do not hesitate to contact me.
I'll be more than happy to help you take care and all the best.